package com.acp.controller;

import com.acp.model.DcsCollectManagement;
import com.acp.param.DcsCollectManagementParam;
import com.acp.param.DcsHistoricalAreaParam;
import com.acp.result.PageResult;
import com.acp.service.DcsCollectManagementService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;
import java.util.List;

/**
 * All rights Reserved, Designed By 姑苏区政府大数据中心
 *
 * @version V1.0
 * @Title: null.java
 * @Package com.dci.controller.construction
 * @Description: 采集管理
 * @author: 张星亮
 * @date: 2019/4/5
 * @Copyright: 2019 姑苏区政府大数据中心. All rights reserved.
 * 注意：本内容仅限于姑苏区政府大数据中心内部传阅，禁止外泄以及用于其他的商业目
 */

@Controller
@RequestMapping("/collectManagement")
public class DcsCollectManagementController {
    @Resource
    private DcsCollectManagementService dcsCollectManagementService;

    /**
     * 查询所有信息
     *
     * @return PageResult 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/queryCollectAll")
    @ResponseBody
    public PageResult queryCollectManagement() {
        PageResult pageResult = dcsCollectManagementService.selectCollect();
        return pageResult;
    }

    /**
     * 插入excel
     * @param request
     * @param proFile
     * @param dcsCollectManagementParam
     * @return PageResult 封装的返回参数  保存成功msg:906 保存失败msg:911
     * @throws Exception
     */
    @RequestMapping(value = "/addCollectAll", method = RequestMethod.POST)
    @ApiOperation(value = "新增", notes = "新增")
    @ApiImplicitParam(paramType = "body", name = "dcsCollectManagementParam", value = "采集数据", required = true, dataType = "DcsCollectManagementParam")
    public @ResponseBody
    String uploadExcel(HttpServletRequest request, @RequestParam("file") MultipartFile proFile, DcsCollectManagementParam dcsCollectManagementParam) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        InputStream inputStream = null;
        List<List<Object>> list = null;
        if (proFile.isEmpty()) {
            return "文件不能为空";
        }
        inputStream = proFile.getInputStream();
        dcsCollectManagementService.getBankListByExcel(inputStream, proFile.getOriginalFilename(), dcsCollectManagementParam);
        inputStream.close();
        return "success";
    }

    /**
     * 查看信息
     * @param dcsCollectManagementParam
     * @return PageResult 封装的返回参数  保存成功msg:906 保存失败msg:911
     */
    @PostMapping("/lookAreaCollect")
    @ResponseBody
    public PageResult queryAreaCollect(@RequestBody DcsCollectManagementParam dcsCollectManagementParam) {
        PageResult pageResult = dcsCollectManagementService.lookCollectArea(dcsCollectManagementParam);
        return pageResult;
    }
}
